Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path/resolver: Fix recursive path resolution #1212

Merged
merged 2 commits into from
May 9, 2015

Conversation

wking
Copy link
Contributor

@wking wking commented May 8, 2015

I'm not entirely clear on Go's scoping (there's some text I can't
quite parse here), but it seems like the := version (because this
is the first time we use 'err') was masking the function-level 'nd'
just for this if block. That means that after we get out of the if
block and return to the start of the for-loop for the next pass,
nd.Links would still be pointing at the original object's links.

This commit drops the :=, which fixes the earlier:

$ ipfs ls QmXX7YRpU7nNBKfw75VG7Y1c3GwpSAGHRev67XVPgZFv9R/static/css
Error: no link named "css" under QmXX7YRpU7nNBKfw75VG7Y1c3GwpSAGHRev67XVPgZFv9R

so we get the intended:

$ ipfs ls QmXX7YRpU7nNBKfw75VG7Y1c3GwpSAGHRev67XVPgZFv9R/static/css
Qme4r3eA4h1revFBgCEv1HF1U7sLL4vvAyzRLWJhCFhwg2 7051 style.css

It also means we're probably missing (or are unreliably using) a
multi-level-path-resolving test.

@jbenet jbenet added the status/in-progress In progress label May 8, 2015
@jbenet
Copy link
Member

jbenet commented May 8, 2015

@wking thanks for fixing. Nasty bug. Yeah we need a test, we should probably include it in this PR.

@wking wking force-pushed the fix-recursive-path-resolution branch from 03db594 to 31b25c2 Compare May 8, 2015 23:23
@wking
Copy link
Contributor Author

wking commented May 8, 2015

On Fri, May 08, 2015 at 04:18:31PM -0700, Juan Batiz-Benet wrote:

Yeah we need a test, we should probably include it in this PR.

Do you know of any two+ layer trees in the example data that could be
used in that test? Or would we need to create that in the test
itself?

@wking wking force-pushed the fix-recursive-path-resolution branch from 31b25c2 to 10669e8 Compare May 8, 2015 23:24
I'm not entirely clear on Go's scoping (there's some text I can't
quite parse here [1]), but it seems like the := version (because this
is the first time we use 'err') was masking the function-level 'nd'
just for this if block.  That means that after we get out of the if
block and return to the start of the for-loop for the next pass,
nd.Links would still be pointing at the original object's links.

This commit drops the :=, which fixes the earlier:

  $ ipfs ls QmXX7YRpU7nNBKfw75VG7Y1c3GwpSAGHRev67XVPgZFv9R/static/css
  Error: no link named "css" under QmXX7YRpU7nNBKfw75VG7Y1c3GwpSAGHRev67XVPgZFv9R

so we get the intended:

  $ ipfs ls QmXX7YRpU7nNBKfw75VG7Y1c3GwpSAGHRev67XVPgZFv9R/static/css
  Qme4r3eA4h1revFBgCEv1HF1U7sLL4vvAyzRLWJhCFhwg2 7051 style.css

It also means we're probably missing (or are unreliably using) a
multi-level-path-resolving test.

[1]: https://golang.org/ref/spec#Declarations_and_scope
@jbenet
Copy link
Member

jbenet commented May 8, 2015

Probably create it (see the pinning test for example)

Setup a three-level graph:

  a -(child)-> b -(grandchild)-> c

and then try and resolve:

  /ipfs/<hash-of-a>/child/grandchild

Before 10669e8 (path/resolver: Fix recursive path resolution,
2015-05-08) this failed with:

  resolver_test.go:71: no link named "grandchild" under QmSomeRandomHash

The boilerplate for this test is from pin/pin_test.go, and I make no
claims that it's the best way to setup the test graph ;).
@wking
Copy link
Contributor Author

wking commented May 9, 2015

On Fri, May 08, 2015 at 04:30:54PM -0700, Juan Batiz-Benet wrote:

Probably create it (see the pinning test for example)

Tests pushed, and I've confirmed that they fail on cd37b67 (the
current master) but pass after 10669e8 (the fix). Not that that's
surprising given the manual command-line tests I mentioned above.

The tests seem to have a high boilerplate-to-meat ratio, so if anyone
sees how to condense them let me know.

@@ -122,7 +122,8 @@ func (s *Resolver) ResolveLinks(ctx context.Context, ndd *merkledag.Node, names
// fetch object for link and assign to nd
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
nd, err := s.DAG.Get(ctx, next)
var err error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change seems unnecessary, but harmless i guess

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, wait, i see now. tricky.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this was the bugfix

@whyrusleeping
Copy link
Member

LGTM, RFM

@jbenet
Copy link
Member

jbenet commented May 9, 2015

this LGTM. is think some of the sharness tests should exercise this too -- in particular ls and refs should test resolution of multiple nodes down

jbenet added a commit that referenced this pull request May 9, 2015
path/resolver: Fix recursive path resolution
@jbenet jbenet merged commit d6fc414 into ipfs:master May 9, 2015
@jbenet jbenet removed the status/in-progress In progress label May 9, 2015
@wking wking deleted the fix-recursive-path-resolution branch May 9, 2015 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants